package com.hmdp.ThreadUtil;

/**
 *@Author:fengxiaohui
 *@Description:
 *@Date:Create in 5:10 下午 2023/6/5
 *@Modified By:
 */
public class ThreadSyncDemo {
    static int count = 0;
    static Object object = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized (object){
                    count++;
                    System.out.println("count ++操作----------> " + count);
                }
            }
        },"t1");
        Thread t2 = new Thread(()->{
            synchronized (object){
            for (int i = 0; i < 10; i++) {

                    count--;
                    System.out.println("count --操作----------> " + count);
                }
            }

        },"t2");
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(count);
    }
}
